if (window.plus) {
    ready();
} else {
    document.addEventListener('plusready', ready, false);
}

$(function () {
    if (AGENT_CLIENT.WEB) {
        ready();
    }
})
function ready() {

    var user = {},
        html = [],
        thisPage = {};
    var messageSetting = function () {
        this.init();
    }
    messageSetting.prototype = {
        init: function () {
          this.initData();
          this.bindEvent();
        },
        initData:function(){
		html.push('<p class="jstz mbbottom">');
		html.push('<span class="jsxx">接收消息通知</span>');
		html.push('<span class="switch-box">');
		var setting;
		if (null == getLocalStorage(STORAGE_MANAGER.reciveMessageSetting)) {
			setLocalStorage(STORAGE_MANAGER.reciveMessageSetting, 1);
		}
		setting = getLocalStorage(STORAGE_MANAGER.reciveMessageSetting);
		html.push('<span id="reciveMessage" class="switch-button ' + ((1==setting) ? 'switch-hover' : '')  + ' ">');	
		html.push('<i></i>');
		html.push('</span>');
		html.push('</span>');
		html.push('</p>');
		html.push('<p class="xxtxing mbbottom">');
		html.push('关闭后，您将收不到来自如此生活的客户端消息通知，由于客户端会提示您 各种优惠及物流等重要信息，建议您开启。需要开启或停用，您可以在 设置 > 通知中心 > 如此生活 中手动设置</p>');
		html.push('<div class="yxtx bgai mbtopbottom">');
		html.push('<p class="yinxiao mbbottom">提示音效</p>');
		html.push('<p class="jstz mbbottom">');
		html.push('<span class="jsxx">铃声提醒</span>');
		html.push('<span class="switch-box">');
		if (null == getLocalStorage(STORAGE_MANAGER.bellsSetting)) {
			setLocalStorage(STORAGE_MANAGER.bellsSetting, 1);
		}		
		setting = getLocalStorage(STORAGE_MANAGER.bellsSetting);
		html.push('<span id="bells" class="switch-button ' + ((1==setting) ? 'switch-hover' : '')  + ' ">');
		html.push('<i></i>');
		html.push('</span>');
		html.push('</span>');
		html.push('</p>');
		html.push('<p class="jstz">');
		html.push('<span class="jsxx">振动提醒</span>');
		html.push('<span class="switch-box">');
		if (null == getLocalStorage(STORAGE_MANAGER.shakeSetting)) {
			setLocalStorage(STORAGE_MANAGER.shakeSetting, 1);
		}
		setting = getLocalStorage(STORAGE_MANAGER.shakeSetting);
		html.push('<span id="shake" class="switch-button ' + ((1==setting) ? 'switch-hover' : '')  + ' ">');
		html.push('<i></i>');
		html.push('</span>');
		html.push('</span>');
		html.push('</span>');
		html.push('</p>');
		html.push('</div>');

		$("#main").html(html.join(''));

        },
        bindEvent: function () {
          //回退
          $("#back").on("click", function () {
              back();
          });
          
          //是否接收消息通知
          $("#main").on("click", "#reciveMessage", function(){
            $(this).toggleClass("switch-hover");
            var setting = $(this).hasClass("switch-hover") ? 1 : 0;
            setLocalStorage(STORAGE_MANAGER.reciveMessageSetting, setting);
          });
          //铃声提醒
          $("#main").on("click", "#bells", function(){
            $(this).toggleClass("switch-hover");
            var setting = $(this).hasClass("switch-hover") ? 1 : 0;
            setLocalStorage(STORAGE_MANAGER.bellsSetting, setting);            
          });
          //震动提醒
          $("#main").on("click", "#shake", function(){
            $(this).toggleClass("switch-hover");
            var setting = $(this).hasClass("switch-hover") ? 1 : 0;
            setLocalStorage(STORAGE_MANAGER.shakeSetting, setting);            
          });
        }
    };

    thisPage = new messageSetting();
}